home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_02_03
/
2n03006a
< prev
next >
Wrap
Text File
|
1991-01-12
|
1KB
|
62 lines
/*
* Listing 1. Initialize the graphics library, draw a
* figure on the screen, and output it to a printer.
* The print_screen() routines are in other listings.
*/
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <graphics.h>
/* prototypes
*/
void print_screen( void );
/* global variables
*/
int x_max, y_max; /* largest X, Y coordinate available */
int print_fh; /* file handle for printer output */
void main( void )
{
int g_driver, g_mode;
/* Open the printer for output, in binary mode.
*/
if ((print_fh = open("PRN", O_WRONLY|O_BINARY)) == -1)
{
printf("Can't open printer!\n");
exit(1);
}
/* Let Turbo C figure out what graphics adapter we're
* using, and initialize it.
*/
detectgraph(&g_driver, &g_mode);
initgraph(&g_driver, &g_mode, "C:\\TC");
/* Get the maximum XY coordinates of this adapter.
*/
x_max = getmaxx();
y_max = getmaxy();
/* Draw a simple figure for testing: a rectangular
* border, a diagonal line, and a circle in the middle.
*/
rectangle(0, 0, x_max, y_max);
line(0, 0, x_max, y_max);
circle(x_max / 2, y_max / 2, y_max / 3);
/* Do the printout (see other listings).
*/
print_screen();
/* Put the screen in text mode, close the printer, and exit.
*/
closegraph();
close(print_fh);
exit(0);
}